package com.credit.service.Impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.credit.common.ServerResponse;
import com.credit.mapper.analysisChartMapper;
import com.credit.mapper.companyMapper;
import com.credit.pojo.analysisChart;
import com.credit.pojo.company;
import com.credit.pojo.user;
import com.credit.service.ICompanyService;
import com.credit.utlis.Tools;
import com.credit.vo.CompanyVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class CompanyServiceImpl implements ICompanyService{

	@Autowired
	private companyMapper companyMapper;

	@Autowired
	private analysisChartMapper analysisChartMapper;
	
	
	public ServerResponse selectCompany(CompanyVo c, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		 
		 List<company> list=companyMapper.selectCompany(c);
		 
		 PageInfo pageInfo = new PageInfo(list);
		
		 return ServerResponse.createBySuccess(pageInfo);
	}



	public ServerResponse insertCompany(company record) {
		record.setCreatortime(Tools.formatDateTime(new Date(), "long"));
		
		companyMapper.insertCompany(record);
		
		analysisChart a=new analysisChart();
		a.setCompanyid(record.getId());
		a.setUserid(record.getCreatoruserid());
		analysisChartMapper.insertAnalysisChart(a);
		
		return ServerResponse.createBySuccess();
	}



	public ServerResponse updateCompany(company record) {
		
		return ServerResponse.createBySuccess(companyMapper.updateCompany(record));
	}



	public ServerResponse selectAuditCompany(CompanyVo c, int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		 
		 List<company> list=companyMapper.selectAuditCompany(c);
		 
		 PageInfo pageInfo = new PageInfo(list);
		
		 return ServerResponse.createBySuccess(pageInfo);
	}



	public ServerResponse selectByPrimaryKey(Integer id) {
		
		return ServerResponse.createBySuccess(companyMapper.selectByPrimaryKey(id));
	}
}
